<?php

/**
 *
 * @author lovebing <lovebing365@126.com> Created on 2015-3-22
 */
class Validation {

    public static function isEmail($email) {
        $exp = '/^[\w\d\-_\.]@([\w\d\-]+.)+[\w]{2,4}$/';
        return preg_match($exp, $email);
    }

    public static function isMobile($mobile) {
        $exp = '/^\+?[\d]{8,14}$/';
        return preg_match($exp, $mobile);
    }

    public static function isPhone($phone) {
        $exp = '/^\+?[\d]{8,15}$/';
        return preg_match($exp, $phone);
    }

    public static function isValidPassword($pwd) {
        $exp = '/^[^\s]{6,20}$/';
        return preg_match($exp, $pwd);
    }
    
    public static function isInt($vals) {
        $exp = '/^[0-9]*[1-9][0-9]*$/';
        return preg_match($exp, $vals);
    }
    
    public static function isFloat($vals) {
        $exp = '/^(?:0|[1-9]\d{0,9})(?:\.(?:[1-9]|\d[1-9]))?$/';
        return preg_match($exp, $vals);
    }
    
    public static function validationByExp($vals,$exp) {
        
        return preg_match($exp, $vals);
    }
    
    /*
     * 顾虑特殊字符 by smh
     */
    public static function replace_specialChar($strParam){
        $regex = "/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/";
        return preg_replace($regex,"",$strParam);
    }
}
